package com.qf.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.dao.MenuItemMapper;
import com.qf.entitys.MenuItem;
import com.qf.service.MenuItemService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MenuItemServiceImpl implements MenuItemService {

    @Resource
    private MenuItemMapper mapper;

    @Override
    public int deleteByPrimaryKey(Integer mid) {
        return mapper.deleteByPrimaryKey(mid);
    }

    @Override
    public int insert(MenuItem record) {
        return 0;
    }

    @Override
    public int insertSelective(MenuItem record) {
        return 0;
    }

    @Override
    public MenuItem selectByPrimaryKey(Integer mid) {
        return null;
    }

    @Override
    public int updateByPrimaryKeySelective(MenuItem record) {
        return mapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKeyWithBLOBs(MenuItem record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(MenuItem record) {
        return 0;
    }

    @Override
    public PageInfo<MenuItem> selectAll(Integer pageindex,MenuItem record) {
        PageHelper.startPage(pageindex,5);
        List<MenuItem> menuItems = mapper.selectAll(record);
        PageInfo<MenuItem> menuItemPageInfo = new PageInfo<>(menuItems);
        return menuItemPageInfo;
    }

    @Override
    public int updatePutByMid(Integer mid, Integer putshelves) {
        return mapper.updatePutByMid(mid,putshelves);
    }

    @Override
    public int updatePutByMids(Integer[] ids, Integer putshelves) {
        for (Integer id : ids) {
            int i = updatePutByMid(id, putshelves);
            if (i==0){
                throw new RuntimeException("修改失败");
            }
        }
        return 1;
    }

    @Override
    public int delbyids(Integer[] ids) {
        for (Integer id : ids) {
            int i = deleteByPrimaryKey(id);
            if (i==0){
                throw new RuntimeException("删除失败");
            }
        }
        return 1;
    }

    @Override
    public PageInfo<MenuItem> selectByBid(Integer bid,Integer pageindex) {
        PageHelper.startPage(pageindex,10);
        List<MenuItem> menuItems = mapper.selectByBid(bid);
        return new PageInfo<>(menuItems);
    }
}
